package net.guerlab.smart.uploader.api.feign.factory;

import feign.hystrix.FallbackFactory;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import net.guerlab.smart.uploader.api.feign.FeignUploadApi;
import net.guerlab.spring.upload.entity.FileInfo;
import net.guerlab.web.result.Fail;
import net.guerlab.web.result.Result;

/**
 * 上传服务快速失败类构建工厂
 *
 * @author guer
 */
public class FeignUploadApiFallbackFactory implements FallbackFactory<FeignUploadApi> {

    @Override
    public FeignUploadApi create(Throwable cause) {
        return new FeignUploadApiFallback(cause);
    }

    /**
     * 上传服务快速失败实现
     */
    @Slf4j
    @AllArgsConstructor
    static class FeignUploadApiFallback implements FeignUploadApi {

        private final Throwable cause;

        @Override
        public Result<FileInfo> base64Single(String fileBase64) {
            log.error("base64Single fallback", cause);
            return new Fail<>("fallback");
        }

        @Override
        public Result<FileInfo> base64Single(String fileBase64, String path) {
            log.error("base64Single fallback", cause);
            return new Fail<>("fallback");
        }
    }
}
